#ifndef _SPRITE_H_
#define _SPRITE_H_


#define BLACK 0
#define WHITE 0xF
#define WALL_COLOR 0x11
extern int HRES;  /**< global variable with the horizontal resolution in pixels */
extern int VRES;  /**< global variable with the vertical resolution in pixels */

/** @defgroup sprite Sprite
 * @{
 *
 * Sprite related functions
 */

/** A Sprite is an "object" that contains all needed information to
 * create, animate, and destroy a pixmap.  The functions assume that
 * the background is BLACK and they take into account collision with
 * other graphical objects or the screen limits. 
 */
typedef struct {
  int x,y;             /**< current sprite position */
  int width, height;   /**< sprite dimensions */
  int xspeed, yspeed;  /**< sprite current speed in the x and y direction */
  char *map;           /**< the sprite pixmap (use read_xpm()) */
  int dirx, diry;	   /**< saves the direction */
} Sprite;

#define MAX_SPEED 5    /**< each sprite maximum speed in pixels/frame */
#define BOTTOM_HIT 1   /**< collision with bottom block          */
#define RIGHT_HIT  2   /**< collision with right block           */
#define LEFT_HIT   3   /**< collision with left block            */
#define UPPER_HIT  4   /**< collision with upper block           */
#define CRASH      6   /**< collision with missiles or the enemy */


/** Reads a xpm-like sprite defined in "map" (look at pixmap.h for
 * examples). Returns the address of the allocated memory where the
 * sprite was read. Updates "width" and "heigh" with the sprite
 * dimension.  Return NULL on error.
 * Assumes that VRES and HRES (the screen vertical and horizontal resolution)
 * are externaly defined.
 * 
 * Usage example, using the defined sprite in pixmap.h:
 * <pre>
 *   #include "pixmap.h" // defines  pic1, pic2, etc 
 *   int wd, hg;
 *   char *sprite = read_xpm(pic1, &wd, &hg);
 * </pre>
*/
char *read_xpm(char *map[], int *width, int *height);

/** Creates with random speeds (not zero) and position
 * (within the screen limits), a new sprite with pixmap "pic", in
 * memory whose address is "base".
 * Returns NULL on invalid pixmap.
 */
Sprite * create_sprite(char *pic[],int posx,int posy,int spx,int spy);

/** Animate the sprite "fig" according to its attributes in memory, 
 * whose address is "base".
 * The animation detects the screen borders
 * and change the speed according; it also detects collision with
 * other objects, including the player pad. Collisions with the screen
 * border generates a perfect reflection, while collision with other
 * objects generates a random perturbation in the object speed. Other
 * strategies can be devised: use quasi-elastic collision based on the
 * objects "mass" and speed, generate spin effect based on amount of
 * tangential speed direction relative to the object center of
 * "mass"...  Returns the kind of collision detected, RIGHT_HIT or
 * LEFT_HIT, if a collision with the players pad (WHITE colored!) is
 * detected.
 */

int animate_sprite(Sprite *fig,int jogador ,int color, char *base);

/** It detects collisions with the screen borders and with other objects.
    Returns the kind of collision detected or Zero if no collision was detected
 */

int check_colisionWalls(Sprite *fig, char *base);
/** The "fig" sprite is erased from memory whose address is "base"
 * and used resources released.
 */
 
 int check_colision(Sprite *fig, char *base);
 
void destroy_sprite(Sprite *fig, char *base);

/** Move in memory whose address is 'base', the 'fig' cursor, a
 * standard sprite, from its current position to a new position
 * 'xstep' and 'ystep' away.  
 * The cursor is erased from its present position in xor-mode and draw
 * in the new position also oin xor-mode.
 * The first time this function is called it only draws the cursor at the
 * current position.
 */ 






void show_sprite(Sprite *fig, char *base);


/** @} end of sprite */

#endif
